home *** CD-ROM | disk | FTP | other *** search
- Subject: Using Counted Ptr objects and Collections?
- Sent: 7/15/96 2:05 AM
- Received: 7/15/96 8:26 AM
- From: Itrat Khan, khan@mustang.uwo.ca
- Reply-To: ODF Interest, ODF-Interest@CILabs.ORG
- To: OpenDoc Development Framework Discussion List, ODF-Interest@CILabs.
-
- I have a question about using pointer-based reference counted objects
- and ordered collections. I admit I don't know my C++ operator
- overloading rules extremely well, so maybe there's a simple solution
- to this problem. :)
-
- I'm using an object that I wish to be both reference-counted (pointer
- based using FW_TCountedPtr) and part of an ordered collection
- (FW_TOrderedCollection). Here are the problems I run into (pretend my
- object's type is called CMyClass):
-
- • FW_TOrderedCollection methods such as AddFirst() require me to
- provide a pointer to an object such as (CMyClass* element).
-
- • The overloaded -> operator for FW_TCountedPtr won't work with a
- pointer to an object. The object has to be declared as (CMyClass
- element).
-
- So I'd have to do something like this:
-
- // ----- Add some arbitrary element to the front of the list. -----
- CMyClass* element = new CMyClass();
- orderedCollection->AddFirst(element);
-
- // ----- Later, retrieve the element and work with it. -----
- element = orderedCollection->First();
- (*element)->GetInfoOrSomething(); // This is what gets messy.
-
- OR
-
- // ----- Add some arbitrary element to the front of the list. -----
- CMyClass element;
- orderedCollection->AddFirst(&element); // This …
-
- // ----- Later, retrieve the element and work with it. -----
- element = * orderedCollection->First(); // … and this are
- messy.
- element->GetInfoOrSomething();
-
- I know the first scenario works and I guess the second will too, I'm
- just wondering if this is the only way I can use these subsystems
- together or if there's a simpler way. I know this is a C++ question,
- but can I overload the -> operator so it would work as follows:
-
- CMyClass* element;
- element->GetInfoOrSomething();
-
- and behind the scenes it really translates the last line to:
-
- element->fRep->GetInfoOrSomething();
-
- I'd appreciate any suggestions, otherwise I'll just use one of the
- above two methods (yuck!) :)
-
- Itrat.
- --
-
-